$dir = "/data2/bsi/RandD/bora/tcga_genotyping/LUSC";
$maindir = "/data2/bsi/RandD/bora/tcga_genotyping";
$temp = "/data2/bsi/RandD/bora/tcga_genotyping/temp";
$sdrf = "$maindir/SRDF/LUSC.sdrf";
$tissue = "LUSC";
open(BUFF,"ls $dir |");
$n = 0;
$m =1;
#readin all the names of the birdseed files and copying to sub directories
system("mkdir $temp");
system("mkdir $temp/$m");
$dir_t = "$temp/$m";
while(<BUFF>)
{
	#print $_;
	chomp($_);
	$n++;
	if($n == 250)
	{
		$m++;
		system("mkdir $temp/$m");
		$dir_t = "$temp/$m";
		$n=0;
	}
	system("cp $dir/$_ $dir_t");
}
for($i=1;$i<=$m;$i++)
{
	$dir_t = "$temp/$i";
	$sys ="perl $maindir/scripts/perl_create_affy_tcga.pl -d $dir_t -a $maindir/ANNOT/GenomeWideSNP_6.na30.annot.csv -t $temp/$i -s $sdrf";
	print $sys."\n";
	system($sys);
	system("/data1/bsi/BORA_processing/genotyping_QC_FWD/bin/plink/plink --tfile $temp/$i --make-bed --out $temp/$i");
}

open(BUFF,">$temp/file.txt") or die "no file exits\n"; 
for($i=2;$i<=$m;$i++)
{
	$dir_t = "$temp/$i";
	print BUFF "$dir_t.bed $dir_t.bim $dir_t.fam\n";
}
system("/data1/bsi/BORA_processing/genotyping_QC_FWD/bin/plink/plink --bfile $temp/1 --merge-list $temp/file.txt --recode --transpose --out $temp/combined");

system("mv $temp/combined.tped $maindir/AFFY/$tissue.tped");
system("mv $temp/combined.tfam $maindir/AFFY/$tissue.tfam");
system("rm -rf $temp/*");
=head
$sys = "perl $maindir/scripts/perl_remove_duplicates_plinkfile.pl -t $maindir/AFFY/fwdStrandResults_BRCA -q $maindir/AFFY/sampleqc_BRCA.tped";
print "$sys\n"; 
system($sys);
#submitting to the program
